
import CryptoJS from 'crypto-js';
let aesKeyInfo = {
    key: '09283fasd124',
    iv: 'abcd12sf123456789', // 密钥偏移量，16个字符
};
let desKeyInfo = {
    key: '0123456234abcdef',
    iv: 'abcdef0123456789', // 密钥偏移量，16个字符
};
let defaultAesMode = CryptoJS.mode.CBC;
let defaultAesPadding = CryptoJS.pad.Pkcs7;
let defaultDesMode = CryptoJS.mode.CBC;
let defaultDesPadding = CryptoJS.pad.Pkcs7;
/** 设置aes默认的密钥和偏移量 */
export function setDefaultAesKeyInfo(keyInfo) {
    aesKeyInfo = keyInfo;
}
/** 设置默认的密钥和偏移量 */
export function setDefaultDesKeyInfo(keyInfo) {
    desKeyInfo = keyInfo;
}
/** 设置默认aes加密模式 */
export function setDefaultAesMode(mode) {
    defaultAesMode = mode;
}
/** 设置默认aes padding模式 */
export function setDefaultAesPadding(padding) {
    defaultAesPadding = padding;
}
/** 设置默认des加密模式 */
export function setDefaultDesMode(mode) {
    defaultDesMode = mode;
}
/** 设置默认des padding模式 */
export function setDefaultDesPadding(padding) {
    defaultDesPadding = padding;
}
/**
 * 加密aes字符串
 */
export function generateSecureDailyPassword(data , { key = aesKeyInfo.key, iv = aesKeyInfo.iv, mode = defaultAesMode, padding = defaultAesPadding, } = {
    key: aesKeyInfo.key,
    iv: aesKeyInfo.iv,
    mode: defaultAesMode,
    padding: defaultAesPadding,
}) {
    const encrypted = CryptoJS.AES.encrypt(getDate(), CryptoJS.enc.Utf8.parse(key), {
        iv: CryptoJS.enc.Utf8.parse(iv),
        mode,
        padding,
    });
    return encrypted.toString().slice(0,10); // 返回的是base64格式的密文
}

function getDate(){
    const currentDate = new Date();
    const year = currentDate.getFullYear();
    const month = (currentDate.getMonth() + 1).toString().padStart(2, '0');
    const day = currentDate.getDate().toString().padStart(2, '0');
    const res = `${year}-${month}-${day}`
    return  res

}
// FfmPI07tprBF5iut8/49zA==